package android.handle;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import winkyle.woodenfish.android.exception.CustomException;
import winkyle.woodenfish.util.ResultUtil;

/**
 * @author winkyle
 * @date 2018/06/22
 * @description 异常拦截器
 */
@ControllerAdvice
public class ExceptionHandle {
	private final Logger logger= LoggerFactory.getLogger(ExceptionHandle.class);
	
	/**
	 * @description 拦截异常，返回异常信息
	 * @param loginException
	 * @return
	 */
	@ExceptionHandler(value = CustomException.class)
	@ResponseBody
	public Object errorHandle(CustomException customException) {
		logger.info(customException.toString());
		return ResultUtil.error(customException.getCode(), customException.getMessage().toString());
	}
}
